/**
 * Global variables and functions
 */
var ProjectName = (function($, window, undefined) {
    var privateVar = 1;

    function privateMethod1() {

    }
    ;

    return {
        publicVar: 1,
        publicObj: {
            var1: 1,
            var2: 2
        },
        publicMethod1: privateMethod1
    };
})(jQuery, window);

/**
 * Website start here
 */
$(document).ready(function() {

    //select all the a tag with name equal to modal
    $('a[name=modal]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr('href');

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        $('#mask').css({'width': maskWidth, 'height': maskHeight});

        //transition effect		
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 1);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(2000);

    });

    //if close button is clicked
    $('a.close').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
    });

    var commentBlock = $('#content');
    commentBlock.undelegate('.item-list > ul.paging > li > a', 'click.paging').delegate('.item-list > ul.paging > li > a', 'click.paging', function(e) {
        e.preventDefault();
        var el = $(this);
        var href = el.attr('href');
        $.ajax({
            type: 'get',
            url: href,
            beforeSend: function() {
                //$('#loading-layer').show();
            },
            success: function(res) {
                //$('#loading-layer').hide();
                try
                {
                    res = $.parseJSON(res);
                    if (res.data) {
                        if ($('.lst-block-wrapper').length)
                            $('.lst-block-wrapper').html(res.data);
                        else
                            $('.primary-jobs').html(res.data);
                    } else if (res.custom_data) {
                        $('.secondary-news > .inner').html(res.custom_data);
                    }
                } catch (e) {
                    $('.lst-block-wrapper').html(res);
                }
            }
        });
    });

    //load ajax for custom page other
    if ($('.loading-custom-page-other').length) {
        var custom_other = $('.loading-custom-page-other');
        $.ajax({
            type: 'get',
            url: custom_other.attr('value'),
            beforeSend: function() {
                //$('#loading-layer').show();
            },
            success: function(res) {
                //$('#loading-layer').hide();
                try
                {
                    res = $.parseJSON(res);
                    if (res.custom_data) {
                        $('.secondary-news > .inner').html(res.custom_data);
                    }
                } catch (e) {
                }
            }
        });
    }

});
